define(['app','pagination','datetime','editor'], function( appCRM ) {
    'use strict';
  /*
  *用户操作日志管理
  */
appCRM.controller('Userlog', function($scope, dataFactoryCRM, $q) {
    $scope.userlogtypes = [{k: 'call',v: '个人通话操作'}, {k: 'event',v: '日程操作'}, {k: 'log',v: '日志操作'},
                       {k: 'userlog',v: '操作日志查看'}, {k: 'right',v: '权限操作'}, {k: 'role',v: '岗位操作'},
                       {k: 'sector',v: '部门操作'}, {k: 'user',v: '员工操作'}, {k: 'goals',v: '营销目标操作'},
                       {k: 'pk',v: 'PK操作'}, {k: 'product',v: '产品操作'}, {k: 'tags',v: '客户标签操作'},
                       {k: 'view360',v: '客户信息操作'}, {k: 'productprice',v: '产品报价操作'}, {k: 'analysis',v: '报表统计'},
                       {k: 'xufei',v: '续费操作'},{k: 'contract',v: '合同操作'}, {k: 'source',v: '渠道操作'},
                       {k: 'complain',v: '投诉操作'},{k: 'money',v: '财务操作'}, {k: 'om',v: 'om操作'},
                       {k: 'customer',v: '客户池操作'},{k: 'pays',v: '查账操作'}];
    $scope.userloglistpage = {pageAll: 1,pageNow: 1, pageSize:20,k: 3};
    $scope.key;
    $scope.msg;
    $scope.create_time;
    $scope.types;

    /**
     * 显示员工操作日志
     * $scope.key:查看方式-我的日志、下属日志; $scope.msg:搜索条件-日志内容
     * $scope.create_time:搜索条件-日志时间; $scope.types:搜索条件-日志类型
     * @return [type] [description]
     */
    $scope.getUserLogList = function(key){
        $scope.$emit("BUSY");
        //切换查看方式：我的日志、下属日志
        if(key) $scope.key = key;
        $scope.msg = document.getElementById('s_msg').value;
        $scope.msg = decodeURI(encodeURI($scope.msg));
        $scope.create_time = document.getElementById('s_time').value;
        $scope.types = document.getElementById('s_type').value;
        //显示数据列表
        var _url = 'userlog/index?key='+$scope.key+'&msg='+$scope.msg+'&type='+$scope.types+'&time='+$scope.create_time;
        _url += '&p=' + $scope.userloglistpage.pageNow + '&psize=' + $scope.userloglistpage.pageSize;
        dataFactoryCRM.getDataByAPI(_url).then(function(_d) {
            $scope.rcode = _d.rcode;
            $scope.userloglistpage.pageSize = _d.psize;
            $scope.userloglistpage.pageAll = _d.pall;
            $scope.userloglistpage.pageNow = _d.p;
            $scope.datalist = _d.data;
            var length1 = _d.data.length;
            for(var i=0;i<length1;i++){
                if(_d.data[i]['request_data'])
                    _d.data[i]['data_content'] = _d.data[i]['request_data'].substring(0,12)+'...';
                if(_d.data[i]['request_url'])
                    _d.data[i]['url_content'] = _d.data[i]['request_url'].substring(0,25)+'...';
                if(_d.data[i]['msg'])
                    _d.data[i]['msg_content'] = _d.data[i]['msg'].substring(0,15)+'...';
            }
            $scope.$emit("NOTBUSY");
        });
     }

    /**
     * 页面自动加载
     */
    $scope.getUserLogList(1);

    /*
    *搜索操作日志
    */
    $scope.search = function(){
        //显示搜索结果列表
        $scope.getUserLogList($scope.key);
    }
  });

});